package com.jingdianjichi.project.domain.service.impl;

import com.alibaba.fastjson.JSON;
import com.jingdianjichi.project.domain.bo.SubjectLabelBo;
import com.jingdianjichi.project.domain.convert.SubjectLabelConverter;
import com.jingdianjichi.project.domain.service.SubjectLabelDomainService;
import com.jingdianjichi.project.infra.basic.entity.SubjectLabel;
import com.jingdianjichi.project.infra.basic.service.SubjectLabelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * ClassName:SubjectCategoryDomainServiceImpl
 * Package:com.jingdianjichi.subject.domain.service.impl
 * Description:
 *
 * @Author fst
 * @Create 2024/9/26 15:39
 * @Version 1.0
 */
@Slf4j
@Service
public class SubjectLabelDomainServiceImpl implements SubjectLabelDomainService
{

    @Resource
    private  SubjectLabelService subjectLabelService;
    public void add(SubjectLabelBo subjectLabelBo)
    {
        //对象转化

        if(log.isInfoEnabled())
        {
            log.info("SubjectLabelController.add.Bo:{}", JSON.toJSONString(subjectLabelBo));
        }
        SubjectLabel subjectLabel = SubjectLabelConverter.
                INSTANCE.
                convertBoToLabel(subjectLabelBo);

        subjectLabelService.insert(subjectLabel);
    }

    public   void update(SubjectLabelBo subjectLabelBo)
    {
        if(log.isInfoEnabled())
        {
            log.info("SubjectLabelController.update.Bo:{}", JSON.toJSONString(subjectLabelBo));
        }
        SubjectLabel subjectLabel = SubjectLabelConverter.
                INSTANCE.
                convertBoToLabel(subjectLabelBo);

        subjectLabelService.update(subjectLabel);
    }

    public void delete(SubjectLabelBo subjectLabelBo)
    {
        if(log.isInfoEnabled())
        {
            log.info("SubjectLabelController.delete.Bo:{}", JSON.toJSONString(subjectLabelBo));
        }
        SubjectLabel subjectLabel = SubjectLabelConverter.
                INSTANCE.
                convertBoToLabel(subjectLabelBo);

        subjectLabelService.delete(subjectLabel);
    }

    public  List<SubjectLabelBo> LabelByCategoryId(SubjectLabelBo subjectLabelBo)
    {
        if(log.isInfoEnabled())
        {
            log.info("SubjectLabelController.LabelByCategoryId.Bo:{}", JSON.toJSONString(subjectLabelBo));
        }
        SubjectLabel subjectLabel = SubjectLabelConverter.
                INSTANCE.
                convertBoToLabel(subjectLabelBo);

        List<SubjectLabel> subjectLabelList=subjectLabelService.queryLabel(subjectLabel);

        return SubjectLabelConverter.INSTANCE.convertBoToLabelList(subjectLabelList);
    }
}
